# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=zeromq
pkgver=4.3.5
pkgrel=2
pkgdesc="The ZeroMQ messaging library and tools"
url="https://zeromq.org/"
arch="all"
license="MPL-2.0"
makedepends="
	asciidoc
	cmake
	libsodium-dev
	perl
	samurai
	util-linux-dev
	xmlto
	"
subpackages="libzmq-static $pkgname-dev libzmq:libs"
source="https://github.com/zeromq/libzmq/releases/download/v$pkgver/zeromq-$pkgver.tar.gz"

# secfixes:
#   4.3.3-r0:
#     - CVE-2020-15166
#   4.3.2-r0:
#     - CVE-2019-13132
#   4.3.1-r0:
#     - CVE-2019-6250

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_TESTS="$(want_check && echo ON || echo OFF)" \
		-DBUILD_STATIC=OFF \
		-DWITH_LIBSODIUM=ON \
		-DENABLE_CURVE=ON \
		-DWITH_DOC=OFF
	cmake --build build

	cmake -B build-static -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_TESTS=OFF \
		-DBUILD_STATIC=ON \
		-DBUILD_SHARED=OFF \
		-DWITH_LIBSODIUM=ON \
		-DWITH_LIBSODIUM_STATIC=ON \
		-DENABLE_CURVE=ON \
		-DWITH_DOC=OFF
	cmake --build build-static
}

check() {
	ulimit -n 2048 # Fix test failure on the builders
	ctest --test-dir build --output-on-failure -E test_security_curve --timeout 300 -j1
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -Dm644 build-static/lib/*.a -t "$pkgdir"/usr/lib
	# just the readme
	rm -r "$pkgdir"/usr/share/zmq
}

sha512sums="
a71d48aa977ad8941c1609947d8db2679fc7a951e4cd0c3a1127ae026d883c11bd4203cf315de87f95f5031aec459a731aec34e5ce5b667b8d0559b157952541  zeromq-4.3.5.tar.gz
"
